<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>理论教学工作量(教师)</title>
    <!-- 引入element-ui样式 -->
    <link rel="stylesheet" href="../../../plugins/element-ui/index.css">

</head>
<body>

<div id="app">
    <el-container style="height: 800px; border: 1px solid #eee">
        <el-container>
            <div style="width: 100%;position: relative">

                <div style=";margin-bottom: 80px;">
                    <el-button type="warning" style="float: right" @click="Up_Add_dialogShow(null)">添加理论教学工作量</el-button>
                </div>

                <el-table   size="medium" current-row-key="id"  :data="dataList" stripe highlight-current-row>
                    <el-table-column type="index" align="center" label="序号"></el-table-column>
                    <el-table-column prop="jobNumber" label="工号" align="center"></el-table-column>
                    <el-table-column prop="name" label="课程名" align="center"></el-table-column>
                    <el-table-column prop="major" label="专业" align="center"></el-table-column>
                    <el-table-column prop="cla" label="班级" align="center"></el-table-column>
                    <el-table-column prop="type" label="授课方式" align="center">
                        <template slot-scope="props">
                            <el-tag v-if="props.row.type == '1'" :type="'success'" disable-transitions>方式一</el-tag>
                            <el-tag v-else-if="props.row.type == '2'" :type="'success'" disable-transitions>方式二</el-tag>
                            <el-tag v-else-if="props.row.type == '3'" :type="'success'" disable-transitions>方式三</el-tag>
                        </template>
                    </el-table-column>
                    <el-table-column prop="studyHour" label="计划学时" align="center"></el-table-column>
                    <el-table-column prop="studentNumber" label="学生数量" align="center"></el-table-column>
                    <el-table-column prop="isRepeat" label="是否重复课程" align="center"></el-table-column>
                    <el-table-column prop="repeatNumber" label="重复课数" align="center"></el-table-column>
                    <el-table-column prop="file" label="附件名" align="center"></el-table-column>
                    <el-table-column prop="describes" label="备注" align="center"></el-table-column>
                    <el-table-column prop="status" label="状态" align="center">
                        <template slot-scope="props">
                            <el-tag v-if="props.row.status == 'true'" :type="'success'" disable-transitions>通过</el-tag>
                            <el-tag v-else-if="props.row.status == 'false'" :type="'primary'" disable-transitions>未通过</el-tag>
                        </template>
                    </el-table-column>
                    <el-table-column prop="grade" label="评分" align="center">
                        <template slot-scope="props">
                            <el-tag v-if="props.row.grade != '0'"  disable-transitions>{{props.row.grade}}</el-tag>
                            <el-tag v-else  disable-transitions>未评定</el-tag>
                        </template>
                    </el-table-column>

                    <el-table-column label="操作" width="200" align="center">
                        <template slot-scope="scope">
                            <el-button type="primary" size="mini" @click="Up_Add_dialogShow(scope.row)">修改</el-button>
                            <el-button type="danger"  size="mini" @click="DeleteTheory(scope.row)">撤销</el-button>
                        </template>
                    </el-table-column>

                </el-table>

                <!--分页组件-->
                <el-pagination
                        class="pagination"
                        @current-change="handleCurrentChange"
                        :current-page="pagination.currentPage"
                        :page-size="pagination.pageSize"
                        layout="total, prev, pager, next, jumper"
                        :total="pagination.total">
                </el-pagination>


                <!--2.修改 理论教学工作量弹框-->
                <el-dialog title="修改" style="height: 650px"  :visible.sync="dialog_update">
                    <el-form :model="formData_update"  ref="formData_update" label-width="100px" class="demo-formData_update">
                        <el-form-item  label="课程名：" prop="name">
                            <el-input v-model="formData_update.name"></el-input>
                        </el-form-item>

                        <el-form-item  label="班级：" prop="cla">
                            <el-input v-model="formData_update.cla"></el-input>
                        </el-form-item>

                        <el-form-item  label="授课方式：" prop="type">
                            <el-select v-model="formData_update.type" placeholder="请选择授课方式">
                                <el-option label="方式一" value="1"></el-option>
                                <el-option label="方式二" value="2"></el-option>
                                <el-option label="方式三" value="3"></el-option>
                            </el-select>
                        </el-form-item>

                        <el-form-item  label="计划学时：" prop="studyHour">
                            <el-input-number v-model="formData_update.studyHour" :min="1" :max="200" label="重复课程次数"></el-input-number>
                        </el-form-item>

                        <el-form-item  label="学生数量：" prop="studentNumber">
                            <el-input-number v-model="formData_update.studentNumber" :min="1" :max="200" label="重复课程次数"></el-input-number>

                        </el-form-item>

                        <el-form-item  label="是否重复课程：" prop="isRepeat">
                            <el-radio-group v-model="formData_update.isRepeat" @change="dd()">
                                <el-radio label="是"></el-radio>
                                <el-radio label="否"></el-radio>
                            </el-radio-group>
                        </el-form-item>

                        <el-form-item  label="重复课数：" prop="repeatNumber" v-show="repeatNumberShow">
                            <el-input-number v-model="formData_update.repeatNumber" :min="1" :max="200" label="重复课程次数"></el-input-number>
                        </el-form-item>

                        <el-form-item  label="附件：" prop="file">
                            <el-upload
                                    class="upload-demo"
                                    action="http://localhost:8080/files/uploadFile2"
                                    :on-preview="handlePreview"
                                    :on-remove="handleRemove"
                                    :before-remove="beforeRemove"
                                    multiple
                                    :limit="3"
                                    :on-exceed="handleExceed"
                                    :on-success="handleAvatarSuccess"
                                    :file-list="fileList">
                                <el-button size="small" type="primary">点击上传</el-button>
                            </el-upload>
                        </el-form-item>

                        <el-form-item  label="备注：" prop="describes">
                            <el-input v-model="formData_update.describes"></el-input>
                        </el-form-item>


                        <el-form-item>
                            <el-button type="primary" @click="UpdateTheory">确定修改</el-button>
                            <el-button @click="center">取消</el-button>
                        </el-form-item>
                    </el-form>
                </el-dialog>

                <!--3.新增 理论教学工作量弹框-->
                <el-dialog title="新增" style="height: 650px"  :visible.sync="dialog_add">
                    <el-form :model="formData_add"  ref="formData_add" label-width="100px" class="demo-formData_add">
                        <el-form-item  label="课程名：" prop="name">
                            <el-input v-model="formData_add.name"></el-input>
                        </el-form-item>
                        <el-form-item  label="班级：" prop="cla">
                            <el-input v-model="formData_add.cla"></el-input>
                        </el-form-item>

                        <el-form-item  label="授课方式：" prop="type">
                            <el-select v-model="formData_add.type" placeholder="请选择授课方式">
                                <el-option label="方式一" value="1"></el-option>
                                <el-option label="方式二" value="2"></el-option>
                                <el-option label="方式三" value="3"></el-option>
                            </el-select>
                        </el-form-item>

                        <el-form-item  label="计划学时：" prop="studyHour">
                            <el-input-number v-model="formData_add.studyHour" :min="1" :max="200" label="重复课程次数"></el-input-number>
                        </el-form-item>

                        <el-form-item  label="学生数量：" prop="studentNumber">
                            <el-input-number v-model="formData_add.studentNumber" :min="1" :max="200" label="重复课程次数"></el-input-number>

                        </el-form-item>

                        <el-form-item  label="是否重复课程：" prop="isRepeat">
                            <el-radio-group v-model="formData_add.isRepeat" @change="dd()">
                                <el-radio label="是"></el-radio>
                                <el-radio label="否"></el-radio>
                            </el-radio-group>
                        </el-form-item>

                        <el-form-item  label="重复课数：" prop="repeatNumber" v-show="repeatNumberShow">
                            <el-input-number v-model="formData_add.repeatNumber" :min="1" :max="200" label="重复课程次数"></el-input-number>
                        </el-form-item>

                        <el-form-item  label="附件：" prop="file">
                            <el-upload
                                    class="upload-demo"
                                    action="http://localhost:8080/files/uploadFile2"
                                    :on-preview="handlePreview"
                                    :on-remove="handleRemove"
                                    :before-remove="beforeRemove"
                                    multiple
                                    :limit="3"
                                    :on-exceed="handleExceed"
                                    :on-success="handleAvatarSuccess"
                                    :file-list="fileList">
                                <el-button size="small" type="primary">点击上传</el-button>
                            </el-upload>
                        </el-form-item>

                        <el-form-item  label="备注：" prop="describes">
                            <el-input v-model="formData_add.describes"></el-input>
                        </el-form-item>


                        <el-form-item>
                            <el-button type="primary" @click="AddTheory">确定添加</el-button>
                            <el-button @click="center">取消</el-button>
                        </el-form-item>
                    </el-form>
                </el-dialog>
            </div>
        </el-container>
    </el-container>
</div>


<script src="../../../plugins/vue/vue.js"></script>

<!-- 引入element-ui组件库 -->
<script src="../../../plugins/element-ui/index.js"></script>

<!-- 引入axios -->
<script src="../../../plugins/axios/axios.min.js"></script>

<script>

    new Vue({
        el:'#app',    //element
        data:{

            teacherInfo:{}, //当前用户信息

            //显示的数据
            dataList:[],

            //element-ui分页插件
            pagination: {//分页相关模型数据 1
                currentPage: 1,//当前页码1
                pageSize:5,//每页显示的记录数1
                total:0,//总记录数1
            },


            //修改弹框内容
            formData_update:{
                file:"",
            },
            dialog_update:false,


            //新增弹框内容
            formData_add:{
                file:"",
                major:"",
            },
            dialog_add:false,

            //文件上传
            fileList: [
                {name: '', url: ''}
            ],

            repeatNumberShow:true,
        },
        created() {
            const teacherInfo = window.localStorage.getItem('teacher')
            console.log("teacherInfo1:::"+teacherInfo)
            if (teacherInfo) {
                this.teacherInfo = JSON.parse(teacherInfo)
            }
            console.log("teacherInfo2:::"+teacherInfo)

            this.getAll();


        },
        methods:{

            dd(){
                console.log(this.formData_update.isRepeat)
                if (this.formData_update.isRepeat=='是' || this.formData_add.isRepeat=='是'){
                   this.repeatNumberShow=true
                }else {
                   this.repeatNumberShow=false
                }
            },
            getAll(){
                console.log("uuid")
                console.log(this.teacherInfo.data)
                console.log(this.teacherInfo.data.jobNumber)

                axios.get("/theorys/getPageTheory/"+this.pagination.currentPage+"/"+this.pagination.pageSize+"/"+this.teacherInfo.data.jobNumber).then((res)=>{
                    console.log(res)
                    this.dataList=res.data.data.records
                    this.pagination.total=res.data.data.total

                })
            },

            //切换页码
            handleCurrentChange(currentPage) {
                console.log("切换页码:")
                this.pagination.currentPage=currentPage;
                console.log(currentPage)
                this.getAll();
            },


            //修改弹框的显示和隐藏
            Up_Add_dialogShow(row){

                this.dd()

                //弹框显示时,先清空弹框
                if (row!==null) {
                    //文件的回显(默认只能上传一个，所以回显也只能回显一个，即设置下标为0的就可以了)
                    this.fileList=[{name:"",url:""}]   //bug：因为点击添加时候已经将fileList制空，里面的‘name’，‘url’已经不存在，所以得重新初始化一下
                        this.fileList[0].name=row.file
                        this.fileList[0].url=`/files/downloadFile?name=${row.file}`

                    //数据回显
                    this.formData_update = row
                    //弹框显示
                    this.dialog_update=true
                }else {
                    this.formData_add={}
                    this.fileList=[]   //将上传的文件制空
                    this.dialog_add=true
                }
            },
            //确定添加
            AddTheory(){
                this.formData_add.jobNumber=this.teacherInfo.data.jobNumber
                this.formData_add.major=this.teacherInfo.data.major
                this.formData_add.grade="0"

                console.log("理论教学工作量添加")
                console.log(this.formData_add)
                axios.post("/theorys/addTheory",this.formData_add).then((res)=> {
                    if (res.data.code){
                        this.$message.success(res.data.msg)
                    }else{
                        this.$message.error(res.data.msg)
                    }
                }).finally(()=>{
                    this.getAll();
                    this.dialog_add=false;
                })
            },

            //确定修改
            UpdateTheory(){
                // this.formData_update=this.teacherInfo.data.jobNumber
                axios.put("/theorys/updateTheory",this.formData_update).then((res)=>{     //修改数据回显
                    if (res.data.code){
                        this.$message.success(res.data.msg)
                    }else{
                        this.$message.error(res.data.msg)
                    }
                }).finally(()=>{
                    this.getAll();
                    this.dialog_update=false;
                })
            },


            //通过id删除
            DeleteTheory(row){
                this.$confirm("此操作撤销当理论教学工作量全部信息，是否继续?","提醒",{type: 'info'
                }).then(()=>{
                    axios.delete("/theorys/deleteTheory/"+row.id).then((res)=> {
                        console.log("deleteById:")
                        console.log(res)
                        if (res.data.code){
                            this.$message.success(res.data.msg)
                        }else{
                            this.$message.error(res.data.msg)
                        }
                    }).finally(()=>{
                        this.getAll()
                    })
                }).catch(()=>{
                    //取消删除
                    this.$message.info("取消删除操作")
                })

            },

            center() {
                this.dialog_update=false
                this.dialog_add=false
                this.$message.info("取消操作")
                this.getAll()
            },

            /**
             * 文件上传
             *
             */
            handleRemove(file, fileList) {
                console.log(file, fileList);
            },
            handlePreview(file) {
                console.log(file);
            },
            handleAvatarSuccess(res, file) {
                 console.log("res,file")
                 console.log(res)
                 console.log(file)
                this.formData_add.file=res.data
                this.formData_update.file=res.data
            },
        }
    })

</script>
</body>
</html>




